﻿#include "game_state_manager.h"
#include <time.h>

CGameStateManager::CGameStateManager(HINSTANCE hInstance, LPWSTR Name, int Mode, bool IsFullScreen, int FrameRate):
	CGame(hInstance, Name, Mode, IsFullScreen, FrameRate)
{
	_CurState = NULL;
	_ScenePlay = NULL;
}

CGameStateManager::~CGameStateManager()
{
	_CurState = NULL;

}

void CGameStateManager::LoadResources(LPDIRECT3DDEVICE9 d3dDevice)
{
	//Khởi tạo màn chơi 
	_ScenePlay = new CScenePlay(_ScreenWidth, _ScreenHeight);
	_ScenePlay->InitElements(d3dDevice);

	_CurState = _ScenePlay;
	_CurState->Show();
}
		
void CGameStateManager::RenderElements(LPDIRECT3DDEVICE9 d3dDevice, int Delta)
{
	d3dDevice->StretchRect(
		_CurState->Background,
		NULL,
		_BackBuffer,
		NULL,
		D3DTEXF_NONE);

	_CurState->DrawElements();
}

void CGameStateManager::UpdateElements(int deltaTime)
{
	_CurState->UpdateElements(deltaTime);
}

void CGameStateManager::ProcessInput(LPDIRECT3DDEVICE9 d3dDevice, int Delta)
{
	_CurState->ProcessInput(d3dDevice,Delta,_KeyStates);
}

void CGameStateManager::OnKeyDown(int KeyCode)
{
	_CurState->OnKeyDown(KeyCode);
}

void CGameStateManager::OnKeyUp(int KeyCode)
{
	_CurState->OnKeyUp(KeyCode);
}
			